﻿using System;
using System.Collections.Generic;

namespace Sandy.Selectors
{
    // Path: client.SuperFamily("name")[keys]
    public class RangeSuperColumnSelector
    {
        private readonly SandyClient _client;
        private readonly SandyFamily _family;
        private readonly IEnumerable<string> _keys;
        private readonly KeyRange _keyRange;

        internal RangeSuperColumnSelector(SandyClient client, SandyFamily family, KeyRange keyRange)
        {
            _client = client;
            _family = family;
            _keyRange = keyRange;

            if (_keyRange == null) throw new ArgumentException("KeyRange cannot be null");
        }

        internal RangeSuperColumnSelector(SandyClient client, SandyFamily family, IEnumerable<string> keys)
        {
            _client = client;
            _family = family;
            _keys = keys;

            if (_keys == null) throw new ArgumentException("Keys cannot be null");
        }

        public SubColumnRangeSelector this[string superCol]
        {
            get
            {
                if (_keyRange != null)
                    return new SubColumnRangeSelector(_client, _family, _keyRange, superCol);

                return new SubColumnRangeSelector(_client, _family, _keys, superCol);
            }
        }

        public IDictionary<string, IDictionary<string, IDictionary<string, string>>> this[IEnumerable<string> superCols]
        {
            get
            {
                // throw new NotImplementedException("request 28: get_range_slices(cf={0}, keyRange={1}, scols={2}");
                if (_keyRange != null)
                    return GetRangeSlicesQuery.PerformSuper(_client, _family, _keyRange, superCols);

                return MultigetSliceQuery.PerformSuper(_client, _family, _keys, superCols);
            }
        }

        public IDictionary<string, IDictionary<string, IDictionary<string, string>>> this[params string[] superCols]
        {
            get
            {
                // Request 29
                return this[(IEnumerable<string>) superCols];
            }
        }

        public IDictionary<string, IDictionary<string, IDictionary<string, string>>> this[Range superCols]
        {
            get
            {
                // throw new NotImplementedException("request 30: get_range_slices(cf={0}, keyRange={1}, scolRange={2}");
                if (_keyRange != null)
                    return GetRangeSlicesQuery.PerformSuper(_client, _family, _keyRange, superCols);

                return MultigetSliceQuery.PerformSuper(_client, _family, _keys, superCols);
            }
        }
    }
}